<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Using Qt Designer &#8212; PyQt 5.8.2 Reference Guide</title>
    
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '5.8.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/logo_tn.ico"/>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="The PyQt5 Resource System" href="resources.html" />
    <link rel="prev" title="Things to be Aware Of" href="gotchas.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="resources.html" title="The PyQt5 Resource System"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="gotchas.html" title="Things to be Aware Of"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">PyQt 5.8.2 Reference Guide</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="using-qt-designer">
<h1>Using Qt Designer<a class="headerlink" href="#using-qt-designer" title="Permalink to this headline">¶</a></h1>
<p>Qt Designer is the Qt tool for designing and building graphical user
interfaces.  It allows you to design widgets, dialogs or complete main windows
using on-screen forms and a simple drag-and-drop interface.  It has the ability
to preview your designs to ensure they work as you intended, and to allow you
to prototype them with your users, before you have to write any code.</p>
<p>Qt Designer uses XML <code class="docutils literal"><span class="pre">.ui</span></code> files to store designs and does not generate any
code itself.  Qt includes the <code class="docutils literal"><span class="pre">uic</span></code> utility that generates the C++ code that
creates the user interface.  Qt also includes the <code class="docutils literal"><span class="pre">QUiLoader</span></code> class that
allows an application to load a <code class="docutils literal"><span class="pre">.ui</span></code> file and to create the corresponding
user interface dynamically.</p>
<p>PyQt5 does not wrap the <code class="docutils literal"><span class="pre">QUiLoader</span></code> class but instead includes the
<a class="reference internal" href="introduction.html#module-PyQt5.uic" title="PyQt5.uic"><code class="xref py py-mod docutils literal"><span class="pre">uic</span></code></a> Python module.  Like <code class="docutils literal"><span class="pre">QUiLoader</span></code> this module can load
<code class="docutils literal"><span class="pre">.ui</span></code> files to create a user interface dynamically.  Like the <strong class="program">uic</strong>
utility it can also generate the Python code that will create the user
interface.  PyQt5&#8217;s <strong class="program">pyuic5</strong> utility is a command line interface to
the <a class="reference internal" href="introduction.html#module-PyQt5.uic" title="PyQt5.uic"><code class="xref py py-mod docutils literal"><span class="pre">uic</span></code></a> module.  Both are described in detail in the following
sections.</p>
<div class="section" id="using-the-generated-code">
<h2>Using the Generated Code<a class="headerlink" href="#using-the-generated-code" title="Permalink to this headline">¶</a></h2>
<p>The code that is generated has an identical structure to that generated by Qt&#8217;s
<code class="docutils literal"><span class="pre">uic</span></code> and can be used in the same way.</p>
<p>The code is structured as a single class that is derived from the Python
<code class="docutils literal"><span class="pre">object</span></code> type.  The name of the class is the name of the toplevel object set
in Designer with <code class="docutils literal"><span class="pre">Ui_</span></code> prepended.  (In the C++ version the class is defined
in the <code class="docutils literal"><span class="pre">Ui</span></code> namespace.)  We refer to this class as the <em>form class</em>.</p>
<p>The class contains a method called <code class="docutils literal"><span class="pre">setupUi()</span></code>.  This takes a single argument
which is the widget in which the user interface is created.  The type of this
argument (typically <a class="reference internal" href="api/qdialog.html#PyQt5.QtWidgets.QDialog" title="PyQt5.QtWidgets.QDialog"><code class="xref py py-class docutils literal"><span class="pre">QDialog</span></code></a>,
<a class="reference internal" href="api/qwidget.html#PyQt5.QtWidgets.QWidget" title="PyQt5.QtWidgets.QWidget"><code class="xref py py-class docutils literal"><span class="pre">QWidget</span></code></a> or <a class="reference internal" href="api/qmainwindow.html#PyQt5.QtWidgets.QMainWindow" title="PyQt5.QtWidgets.QMainWindow"><code class="xref py py-class docutils literal"><span class="pre">QMainWindow</span></code></a>) is
set in Designer.  We refer to this type as the <em>Qt base class</em>.</p>
<p>In the following examples we assume that a <code class="docutils literal"><span class="pre">.ui</span></code> file has been created
containing a dialog and the name of the <a class="reference internal" href="api/qdialog.html#PyQt5.QtWidgets.QDialog" title="PyQt5.QtWidgets.QDialog"><code class="xref py py-class docutils literal"><span class="pre">QDialog</span></code></a>
object is <code class="docutils literal"><span class="pre">ImageDialog</span></code>.  We also assume that the name of the file containing
the generated Python code is <code class="file docutils literal"><span class="pre">ui_imagedialog.py</span></code>.  The generated code can
then be used in a number of ways.</p>
<p>The first example shows the direct approach where we simply create a simple
application to create the dialog:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">PyQt5.QtWidgets</span> <span class="k">import</span> <span class="n">QApplication</span><span class="p">,</span> <span class="n">QDialog</span>
<span class="kn">from</span> <span class="nn">ui_imagedialog</span> <span class="k">import</span> <span class="n">Ui_ImageDialog</span>

<span class="n">app</span> <span class="o">=</span> <span class="n">QApplication</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
<span class="n">window</span> <span class="o">=</span> <span class="n">QDialog</span><span class="p">()</span>
<span class="n">ui</span> <span class="o">=</span> <span class="n">Ui_ImageDialog</span><span class="p">()</span>
<span class="n">ui</span><span class="o">.</span><span class="n">setupUi</span><span class="p">(</span><span class="n">window</span><span class="p">)</span>

<span class="n">window</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">exec_</span><span class="p">())</span>
</pre></div>
</div>
<p>The second example shows the single inheritance approach where we sub-class
<a class="reference internal" href="api/qdialog.html#PyQt5.QtWidgets.QDialog" title="PyQt5.QtWidgets.QDialog"><code class="xref py py-class docutils literal"><span class="pre">QDialog</span></code></a> and set up the user interface in the
<code class="docutils literal"><span class="pre">__init__()</span></code> method:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">PyQt5.QtWidgets</span> <span class="k">import</span> <span class="n">QDialog</span>
<span class="kn">from</span> <span class="nn">ui_imagedialog</span> <span class="k">import</span> <span class="n">Ui_ImageDialog</span>

<span class="k">class</span> <span class="nc">ImageDialog</span><span class="p">(</span><span class="n">QDialog</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">ImageDialog</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Set up the user interface from Designer.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ui</span> <span class="o">=</span> <span class="n">Ui_ImageDialog</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">setupUi</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c1"># Make some local modifications.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">colorDepthCombo</span><span class="o">.</span><span class="n">addItem</span><span class="p">(</span><span class="s2">&quot;2 colors (1 bit per pixel)&quot;</span><span class="p">)</span>

        <span class="c1"># Connect up the buttons.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">okButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">accept</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">cancelButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reject</span><span class="p">)</span>
</pre></div>
</div>
<p>The third example shows the multiple inheritance approach:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">PyQt5.QtGui</span> <span class="k">import</span> <span class="n">QDialog</span>
<span class="kn">from</span> <span class="nn">ui_imagedialog</span> <span class="k">import</span> <span class="n">Ui_ImageDialog</span>

<span class="k">class</span> <span class="nc">ImageDialog</span><span class="p">(</span><span class="n">QDialog</span><span class="p">,</span> <span class="n">Ui_ImageDialog</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">ImageDialog</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Set up the user interface from Designer.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setupUi</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c1"># Make some local modifications.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">colorDepthCombo</span><span class="o">.</span><span class="n">addItem</span><span class="p">(</span><span class="s2">&quot;2 colors (1 bit per pixel)&quot;</span><span class="p">)</span>

        <span class="c1"># Connect up the buttons.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">okButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">accept</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cancelButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reject</span><span class="p">)</span>
</pre></div>
</div>
<p>It is also possible to use the same approach used in PyQt v3.  This is shown in
the final example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">ui_imagedialog</span> <span class="k">import</span> <span class="n">ImageDialog</span>

<span class="k">class</span> <span class="nc">MyImageDialog</span><span class="p">(</span><span class="n">ImageDialog</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MyImageDialog</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Make some local modifications.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">colorDepthCombo</span><span class="o">.</span><span class="n">addItem</span><span class="p">(</span><span class="s2">&quot;2 colors (1 bit per pixel)&quot;</span><span class="p">)</span>

        <span class="c1"># Connect up the buttons.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">okButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">accept</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cancelButton</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reject</span><span class="p">)</span>
</pre></div>
</div>
<p>For a full description see the Qt Designer Manual in the Qt Documentation.</p>
</div>
<div class="section" id="the-uic-module">
<h2>The <a class="reference internal" href="introduction.html#module-PyQt5.uic" title="PyQt5.uic"><code class="xref py py-mod docutils literal"><span class="pre">uic</span></code></a> Module<a class="headerlink" href="#the-uic-module" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="introduction.html#module-PyQt5.uic" title="PyQt5.uic"><code class="xref py py-mod docutils literal"><span class="pre">uic</span></code></a> module contains the following functions and objects.</p>
<dl class="data">
<dt id="PyQt5.uic.widgetPluginPath">
<code class="descclassname">PyQt5.uic.</code><code class="descname">widgetPluginPath</code><a class="headerlink" href="#PyQt5.uic.widgetPluginPath" title="Permalink to this definition">¶</a></dt>
<dd><p>The list of the directories that are searched for widget plugins.
Initially it contains the name of the directory that contains the widget
plugins included with PyQt5.</p>
</dd></dl>

<dl class="function">
<dt id="PyQt5.uic.compileUi">
<code class="descclassname">PyQt5.uic.</code><code class="descname">compileUi</code><span class="sig-paren">(</span><em>uifile</em>, <em>pyfile</em><span class="optional">[</span>, <em>execute=False</em><span class="optional">[</span>, <em>indent=4</em><span class="optional">[</span>, <em>from_imports=False</em><span class="optional">[</span>, <em>resource_suffix='_rc'</em><span class="optional">[</span>, <em>import_from='.'</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#PyQt5.uic.compileUi" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a Python module that will create a user interface from a Qt
Designer <code class="docutils literal"><span class="pre">.ui</span></code> file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>uifile</strong> &#8211; the file name or file-like object containing the <code class="docutils literal"><span class="pre">.ui</span></code> file.</li>
<li><strong>pyfile</strong> &#8211; the file-like object to which the generated Python code will be written
to.</li>
<li><strong>execute</strong> &#8211; is optionally set if a small amount of additional code is to be
generated that will display the user interface if the code is run as a
standalone application.</li>
<li><strong>indent</strong> &#8211; the optional number of spaces used for indentation in the generated
code.  If it is zero then a tab character is used instead.</li>
<li><strong>from_imports</strong> &#8211; is optionally set to generate relative import statements.  At the
moment this only applies to the import of resource modules.</li>
<li><strong>import_from</strong> &#8211; is optionally set to the package used for relative import statements.
The default is <code class="docutils literal"><span class="pre">'.'</span></code>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Resource_suffix:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body"><p class="first last">is the suffix appended to the basename of any resource file specified
in the <code class="docutils literal"><span class="pre">.ui</span></code> file to create the name of the Python module generated
from the resource file by <code class="docutils literal"><span class="pre">pyrcc5</span></code>.  The default is <code class="docutils literal"><span class="pre">'_rc'</span></code>, i.e.
if the <code class="docutils literal"><span class="pre">.ui</span></code> file specified a resource file called <code class="docutils literal"><span class="pre">foo.qrc</span></code> then
the corresponding Python module is <code class="docutils literal"><span class="pre">foo_rc</span></code>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="PyQt5.uic.compileUiDir">
<code class="descclassname">PyQt5.uic.</code><code class="descname">compileUiDir</code><span class="sig-paren">(</span><em>dir</em><span class="optional">[</span>, <em>recurse=False</em><span class="optional">[</span>, <em>map=None</em><span class="optional">[</span>, <em>**compileUi_args</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#PyQt5.uic.compileUiDir" title="Permalink to this definition">¶</a></dt>
<dd><p>Create Python modules from Qt Designer <code class="docutils literal"><span class="pre">.ui</span></code> files in a directory or
directory tree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>dir</strong> &#8211; the name of the directory to scan for files whose name ends with
<code class="docutils literal"><span class="pre">.ui</span></code>.  By default the generated Python module is created in the same
directory ending with <code class="docutils literal"><span class="pre">.py</span></code>.</li>
<li><strong>recurse</strong> &#8211; is optionally set if any sub-directories should be scanned.</li>
<li><strong>map</strong> &#8211; an optional callable that is passed the name of the directory
containing the <code class="docutils literal"><span class="pre">.ui</span></code> file and the name of the Python module that will
be created.  The callable should return a tuple of the name of the
directory in which the Python module will be created and the (possibly
modified) name of the module.</li>
<li><strong>compileUi_args</strong> &#8211; are any additional keyword arguments that are passed to
<a class="reference internal" href="#PyQt5.uic.compileUi" title="PyQt5.uic.compileUi"><code class="xref py py-func docutils literal"><span class="pre">compileUi()</span></code></a> that is called to create each Python
module.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="PyQt5.uic.loadUiType">
<code class="descclassname">PyQt5.uic.</code><code class="descname">loadUiType</code><span class="sig-paren">(</span><em>uifile</em><span class="optional">[</span>, <em>from_imports=False</em><span class="optional">[</span>, <em>resource_suffix='_rc'</em><span class="optional">[</span>, <em>import_from='.'</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#PyQt5.uic.loadUiType" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a Qt Designer <code class="docutils literal"><span class="pre">.ui</span></code> file and return a tuple of the generated
<em>form class</em> and the <em>Qt base class</em>.  These can then be used to
create any number of instances of the user interface without having to
parse the <code class="docutils literal"><span class="pre">.ui</span></code> file more than once.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>uifile</strong> &#8211; the file name or file-like object containing the <code class="docutils literal"><span class="pre">.ui</span></code> file.</li>
<li><strong>from_imports</strong> &#8211; is optionally set to generate relative import statements.  At the
moment this only applies to the import of resource modules.</li>
<li><strong>import_from</strong> &#8211; is optionally set to the package used for relative import statements.
The default is <code class="docutils literal"><span class="pre">'.'</span></code>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Resource_suffix:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body"><p class="first">is the suffix appended to the basename of any resource file specified
in the <code class="docutils literal"><span class="pre">.ui</span></code> file to create the name of the Python module generated
from the resource file by <code class="docutils literal"><span class="pre">pyrcc5</span></code>.  The default is <code class="docutils literal"><span class="pre">'_rc'</span></code>, i.e.
if the <code class="docutils literal"><span class="pre">.ui</span></code> file specified a resource file called <code class="docutils literal"><span class="pre">foo.qrc</span></code> then
the corresponding Python module is <code class="docutils literal"><span class="pre">foo_rc</span></code>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">the <em>form class</em> and the <em>Qt base class</em>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="PyQt5.uic.loadUi">
<code class="descclassname">PyQt5.uic.</code><code class="descname">loadUi</code><span class="sig-paren">(</span><em>uifile</em><span class="optional">[</span>, <em>baseinstance=None</em><span class="optional">[</span>, <em>package=''</em><span class="optional">[</span>, <em>resource_suffix='_rc'</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#PyQt5.uic.loadUi" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a Qt Designer <code class="docutils literal"><span class="pre">.ui</span></code> file and returns an instance of the user
interface.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>uifile</strong> &#8211; the file name or file-like object containing the <code class="docutils literal"><span class="pre">.ui</span></code> file.</li>
<li><strong>baseinstance</strong> &#8211; the optional instance of the <em>Qt base class</em>.  If specified then the
user interface is created in it.  Otherwise a new instance of the base
class is automatically created.</li>
<li><strong>package</strong> &#8211; the optional package that is the base package for any relative imports
of custom widgets.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Resource_suffix:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body"><p class="first">is the suffix appended to the basename of any resource file specified
in the <code class="docutils literal"><span class="pre">.ui</span></code> file to create the name of the Python module generated
from the resource file by <code class="docutils literal"><span class="pre">pyrcc5</span></code>.  The default is <code class="docutils literal"><span class="pre">'_rc'</span></code>, i.e.
if the <code class="docutils literal"><span class="pre">.ui</span></code> file specified a resource file called <code class="docutils literal"><span class="pre">foo.qrc</span></code> then
the corresponding Python module is <code class="docutils literal"><span class="pre">foo_rc</span></code>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">the <code class="docutils literal"><span class="pre">QWidget</span></code> sub-class that implements the user interface.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="pyuic5">
<h2><strong class="program">pyuic5</strong><a class="headerlink" href="#pyuic5" title="Permalink to this headline">¶</a></h2>
<p>The <strong class="program">pyuic5</strong> utility is a command line interface to the
<a class="reference internal" href="introduction.html#module-PyQt5.uic" title="PyQt5.uic"><code class="xref py py-mod docutils literal"><span class="pre">uic</span></code></a> module.  The command has the following syntax:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pyuic5</span> <span class="p">[</span><span class="n">options</span><span class="p">]</span> <span class="o">.</span><span class="n">ui</span><span class="o">-</span><span class="n">file</span>
</pre></div>
</div>
<p>The full set of command line options is:</p>
<dl class="cmdoption">
<dt id="cmdoption-pyuic5-h">
<code class="descname">-h</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--help</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-pyuic5-h" title="Permalink to this definition">¶</a></dt>
<dd><p>A help message is written to <code class="docutils literal"><span class="pre">stdout</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-version">
<code class="descname">--version</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-pyuic5-version" title="Permalink to this definition">¶</a></dt>
<dd><p>The version number is written to <code class="docutils literal"><span class="pre">stdout</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-i">
<code class="descname">-i</code><code class="descclassname"> &lt;N&gt;</code><code class="descclassname">, </code><code class="descname">--indent</code><code class="descclassname"> &lt;N&gt;</code><a class="headerlink" href="#cmdoption-pyuic5-i" title="Permalink to this definition">¶</a></dt>
<dd><p>The Python code is generated using an indentation of <code class="docutils literal"><span class="pre">&lt;N&gt;</span></code> spaces.  If
<code class="docutils literal"><span class="pre">&lt;N&gt;</span></code> is 0 then a tab is used.  The default is 4.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-o">
<code class="descname">-o</code><code class="descclassname"> &lt;FILE&gt;</code><code class="descclassname">, </code><code class="descname">--output</code><code class="descclassname"> &lt;FILE&gt;</code><a class="headerlink" href="#cmdoption-pyuic5-o" title="Permalink to this definition">¶</a></dt>
<dd><p>The Python code generated is written to the file <code class="docutils literal"><span class="pre">&lt;FILE&gt;</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-p">
<code class="descname">-p</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--preview</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-pyuic5-p" title="Permalink to this definition">¶</a></dt>
<dd><p>The GUI is created dynamically and displayed.  No Python code is generated.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-x">
<code class="descname">-x</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--execute</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-pyuic5-x" title="Permalink to this definition">¶</a></dt>
<dd><p>The generated Python code includes a small amount of additional code that
creates and displays the GUI when it is executes as a standalone
application.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-import-from">
<code class="descname">--import-from</code><code class="descclassname"> &lt;PACKAGE&gt;</code><a class="headerlink" href="#cmdoption-pyuic5-import-from" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 5.6.</span></p>
</div>
<p>Resource modules are imported using <code class="docutils literal"><span class="pre">from</span> <span class="pre">&lt;PACKAGE&gt;</span> <span class="pre">import</span> <span class="pre">...</span></code> rather
than a simple <code class="docutils literal"><span class="pre">import</span> <span class="pre">...</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-from-imports">
<code class="descname">--from-imports</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-pyuic5-from-imports" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the equivalent of specifying <code class="docutils literal"><span class="pre">--import-from</span> <span class="pre">.</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-pyuic5-resource-suffix">
<code class="descname">--resource-suffix</code><code class="descclassname"> &lt;SUFFIX&gt;</code><a class="headerlink" href="#cmdoption-pyuic5-resource-suffix" title="Permalink to this definition">¶</a></dt>
<dd><p>The suffix <code class="docutils literal"><span class="pre">&lt;SUFFIX&gt;</span></code> is appended to the basename of any resource file
specified in the <code class="docutils literal"><span class="pre">.ui</span></code> file to create the name of the Python module
generated from the resource file by <strong class="program">pyrcc5</strong>.  The default is
<code class="docutils literal"><span class="pre">_rc</span></code>.  For example if the <code class="docutils literal"><span class="pre">.ui</span></code> file specified a resource file called
<code class="docutils literal"><span class="pre">foo.qrc</span></code> then the corresponding Python module is <code class="docutils literal"><span class="pre">foo_rc</span></code>.</p>
</dd></dl>

<p>Note that code generated by <strong class="program">pyuic5</strong> is not guaranteed to be
compatible with earlier versions of PyQt5.  However, it is guaranteed to be
compatible with later versions.  If you have no control over the version of
PyQt5 the users of your application are using then you should run
<strong class="program">pyuic5</strong>, or call <a class="reference internal" href="#PyQt5.uic.compileUi" title="PyQt5.uic.compileUi"><code class="xref py py-func docutils literal"><span class="pre">compileUi()</span></code></a>, as part of your
installation process.  Another alternative would be to distribute the <code class="docutils literal"><span class="pre">.ui</span></code>
files (perhaps as part of a resource file) and have your application load them
dynamically.</p>
</div>
<div class="section" id="writing-qt-designer-plugins">
<span id="ref-designer-plugins"></span><h2>Writing Qt Designer Plugins<a class="headerlink" href="#writing-qt-designer-plugins" title="Permalink to this headline">¶</a></h2>
<p>Qt Designer can be extended by writing plugins.  Normally this is done using
C++ but PyQt5 also allows you to write plugins in Python.  Most of the time a
plugin is used to expose a custom widget to Designer so that it appears in
Designer&#8217;s widget box just like any other widget.  It is possibe to change the
widget&#8217;s properties and to connect its signals and slots.</p>
<p>It is also possible to add new functionality to Designer.  See the Qt
documentation for the full details.  Here we will concentrate on describing
how to write custom widgets in Python.</p>
<p>The process of integrating Python custom widgets with Designer is very similar
to that used with widget written using C++.  However, there are particular
issues that have to be addressed.</p>
<ul class="simple">
<li>Designer needs to have a C++ plugin that conforms to the interface defined by
the <code class="docutils literal"><span class="pre">QDesignerCustomWidgetInterface</span></code> class.  (If the plugin exposes more
than one custom widget then it must conform to the interface defined by the
<code class="docutils literal"><span class="pre">QDesignerCustomWidgetCollectionInterface</span></code> class.)  In addition the plugin
class must sub-class <a class="reference internal" href="api/qobject.html#PyQt5.QtCore.QObject" title="PyQt5.QtCore.QObject"><code class="xref py py-class docutils literal"><span class="pre">QObject</span></code></a> as well as the interface
class.  PyQt5 does not allow Python classes to be sub-classed from more than
one Qt class.</li>
<li>Designer can only connect Qt signals and slots.  It has no understanding of
Python signals or callables.</li>
<li>Designer can only edit Qt properties that represent C++ types.  It has no
understanding of Python attributes or Python types.</li>
</ul>
<p>PyQt5 provides the following components and features to resolve these issues as
simply as possible.</p>
<ul>
<li><p class="first">PyQt5&#8217;s QtDesigner module includes additional classes (all of which have a
<code class="docutils literal"><span class="pre">QPy</span></code> prefix) that are already sub-classed from the necessary Qt classes.
This avoids the need to sub-class from more than one Qt class in Python.  For
example, where a C++ custom widget plugin would sub-class from
<a class="reference internal" href="api/qobject.html#PyQt5.QtCore.QObject" title="PyQt5.QtCore.QObject"><code class="xref py py-class docutils literal"><span class="pre">QObject</span></code></a> and <code class="docutils literal"><span class="pre">QDesignerCustomWidgetInterface</span></code>, a
Python custom widget plugin would instead sub-class from
<code class="xref py py-class docutils literal"><span class="pre">QPyDesignerCustomWidgetPlugin</span></code>.</p>
</li>
<li><p class="first">PyQt5 installs a C++ plugin in Designer&#8217;s plugin directory.  It conforms to
the interface defined by the <code class="docutils literal"><span class="pre">QDesignerCustomWidgetCollectionInterface</span></code>
class.  It searches a configurable set of directories looking for Python
plugins that implement a class sub-classed from
<code class="xref py py-class docutils literal"><span class="pre">QPyDesignerCustomWidgetPlugin</span></code>.  Each class that is
found is instantiated and the instance created is added to the custom widget
collection.</p>
<p>The <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYQTDESIGNERPATH</span></code> environment variable specifies the set of
directories to search for plugins.  Directory names are separated by a path
separator (a semi-colon on Windows and a colon on other platforms).  If a
directory name is empty (ie. there are consecutive path separators or a
leading or trailing path separator) then a set of default directories is
automatically inserted at that point.  The default directories are the
<code class="file docutils literal"><span class="pre">python</span></code> subdirectory of each directory that Designer searches for its
own plugins.  If the environment variable is not set then only the default
directories are searched.  If a file&#8217;s basename does not end with <code class="docutils literal"><span class="pre">plugin</span></code>
then it is ignored.</p>
</li>
<li><p class="first">A Python custom widget may define new Qt signals using
<a class="reference internal" href="signals_slots.html#PyQt5.QtCore.pyqtSignal" title="PyQt5.QtCore.pyqtSignal"><code class="xref py py-func docutils literal"><span class="pre">pyqtSignal()</span></code></a>.</p>
</li>
<li><p class="first">A Python method may be defined as a new Qt slot by using the
<a class="reference internal" href="signals_slots.html#PyQt5.QtCore.pyqtSlot" title="PyQt5.QtCore.pyqtSlot"><code class="xref py py-func docutils literal"><span class="pre">pyqtSlot()</span></code></a> decorator.</p>
</li>
<li><p class="first">A new Qt property may be defined using the <a class="reference internal" href="qt_properties.html#PyQt5.QtCore.pyqtProperty" title="PyQt5.QtCore.pyqtProperty"><code class="xref py py-func docutils literal"><span class="pre">pyqtProperty()</span></code></a>
function.</p>
</li>
</ul>
<p>Note that the ability to define new Qt signals, slots and properties from
Python is potentially useful to plugins conforming to any plugin interface and
not just that used by Designer.</p>
<p>For a simple but complete and fully documented example of a custom widget that
defines new Qt signals, slots and properties, and its plugin, look in the
<code class="file docutils literal"><span class="pre">examples/designer/plugins</span></code> directory of the PyQt5 source package.  The
<code class="file docutils literal"><span class="pre">widgets</span></code> subdirectory contains the <code class="file docutils literal"><span class="pre">pydemo.py</span></code> custom widget and
the <code class="file docutils literal"><span class="pre">python</span></code> subdirectory contains its <code class="file docutils literal"><span class="pre">pydemoplugin.py</span></code> plugin.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Using Qt Designer</a><ul>
<li><a class="reference internal" href="#using-the-generated-code">Using the Generated Code</a></li>
<li><a class="reference internal" href="#the-uic-module">The <code class="docutils literal"><span class="pre">uic</span></code> Module</a></li>
<li><a class="reference internal" href="#pyuic5"><strong class="program">pyuic5</strong></a></li>
<li><a class="reference internal" href="#writing-qt-designer-plugins">Writing Qt Designer Plugins</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="gotchas.html"
                        title="previous chapter">Things to be Aware Of</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="resources.html"
                        title="next chapter">The PyQt5 Resource System</a></p>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="resources.html" title="The PyQt5 Resource System"
             >next</a> |</li>
        <li class="right" >
          <a href="gotchas.html" title="Things to be Aware Of"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">PyQt 5.8.2 Reference Guide</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2015 Riverbank Computing Limited.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.3.
    </div>
  </body>
</html>